﻿#light

namespace CodeBlock

open System

module public Utils =
    let make_value opt value =
        match opt with
        | Some(value) -> value
        | None -> value
    
    let inline bound value low high name =
        if (value < low) || (value > high) then raise(ArgumentOutOfRangeException(name))
    
    let inline int_size value =
        let value = int64(value)
        if value = int64(sbyte(value)) then 1
        elif value = int64(int16(value)) then 2
        elif value = int64(int(value)) then 4
        else 8
    
    let inline uint_size value =
        let value = uint64(value)
        if value = uint64(byte(value)) then 1
        elif value = uint64(uint16(value)) then 2
        elif value = uint64(uint32(value)) then 4
        else 8